<?php
/**
 * 
 * @param number $coursesid
 * @param string $title
 * @param string $sumary
 * @return Ambigous <number, false, boolean, mixed>
 */
function seitcm_add_curriculum($coursesid,$other,$title,$sumary) {
	global $wpdb;
	return $wpdb->query($wpdb->prepare('INSERT INTO ' . SEITCM_TABLE_CURRICULUM . '(coursesid,`order`,title,sumary) VALUES (%d,%d,%s,%s)',$coursesid,$other,$title,$sumary));
}
/**
 * 
 * @param unknown $id
 * @param unknown $other
 * @param unknown $title
 * @param unknown $sumary
 * @return boolean|Ambigous <number, false, boolean, mixed>
 */
function seitcm_update_curriculum($id,$other,$title,$sumary) {
	global $wpdb;
	if(seitcm_update_same_data_curriculum($id,$other,$title,$sumary)) return true;
	return $wpdb->query($wpdb->prepare('UPDATE ' . SEITCM_TABLE_CURRICULUM . ' SET `order` = %d, title = %s, sumary = %s WHERE id = %d',$other,$title,$sumary,$id));
}
/**
 * 
 * @param unknown $id
 * @param unknown $other
 * @param unknown $title
 * @param unknown $sumary
 * @return boolean
 */
function seitcm_update_same_data_curriculum($id,$other,$title,$sumary)
{
	$result = seitcm_get_single_curriculum($id);
	if($other==$result->order && $title==$result->title && $sumary==$result->sumary) return true;
	return false;
}
/**
 * 
 * @param unknown $coursesid
 * @return Ambigous <mixed, NULL, multitype:, multitype:multitype: , multitype:Ambigous <multitype:, NULL> >
 */
function seitcm_get_curriculum_for_courses($coursesid)
{
	global $wpdb;
	return $wpdb->get_results($wpdb->prepare('SELECT * FROM ' . SEITCM_TABLE_CURRICULUM . ' WHERE `coursesid` = %d ORDER BY `order`',$coursesid));
}
/**
 * 
 * @param unknown $coursesid
 * @return Ambigous <mixed, NULL, multitype:>
 */
function seitcm_get_single_curriculum($id)
{
	global $wpdb;
	return $wpdb->get_row($wpdb->prepare('SELECT * FROM ' . SEITCM_TABLE_CURRICULUM . ' WHERE `id` = %d',$id));
}
/**
 * 
 * @param unknown $coursesid
 * @return Ambigous <mixed, NULL, multitype:>
 */
function seitcm_enable_single_curriculum($id)
{
	global $wpdb;
	return $wpdb->query($wpdb->prepare('UPDATE ' . SEITCM_TABLE_CURRICULUM . ' SET status = 1 WHERE `id` = %d',$id));
}
/**
 * 
 * @param unknown $coursesid
 * @return Ambigous <mixed, NULL, multitype:>
 */
function seitcm_remove_single_curriculum($id)
{
	global $wpdb;
	return $wpdb->query($wpdb->prepare('DELETE FROM ' . SEITCM_TABLE_CURRICULUM . ' WHERE `id` = %d',$id));
}
/**
 * 
 * @param unknown $coursesid
 * @return Ambigous <mixed, NULL, multitype:>
 */
function seitcm_get_last_curriculum_for_courses($coursesid)
{
	global $wpdb;
	return $wpdb->get_row($wpdb->prepare('SELECT * FROM ' . SEITCM_TABLE_CURRICULUM . ' WHERE `coursesid` = %d ORDER BY `order` DESC',$coursesid));
}
/**
 * 
 * @param unknown $coursesid
 * @return number
 */
function seitcm_get_last_curriculum_order_for_courses($coursesid)
{
	$last = seitcm_get_last_curriculum_for_courses($coursesid);
	if($last!=NULL)	return $last->order;
	return 0;
}
?>